define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'test/hld/answer/index',
                    add_url: 'test/hld/answer/add',
                    edit_url: 'test/hld/answer/edit',
                    del_url: 'test/hld/answer/del',
                    multi_url: 'test/hld/answer/multi',
                    table: 'test_hld_answer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'user_nickname', title: __('姓名'),operate:false},
                        {field: 'user_mobile', title: __('手机'),operate:false},
                        {field: 'create_time', title: __('测试时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'buttons', title: __('查看详情'),formatter: Controller.api.formatter.viewreport,operate:false},
                        // {field: 'buttons', title: __('下载报告'),formatter: Controller.api.formatter.download,operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                viewreport: function (value,row,index) {
                    if(row.user_id){
                        return '<a target="_blank" class="btn btn-success btn-file btn-xs" href="/index/testing/hldtestreport?from=admin&uid='+row.user_id+'">查看详情</a>';
                    }else{
                        return '-';
                    }
                },
                download: function (value,row,index) {
                    if(row.user_id){
                        return '<a target="_blank" class="btn btn-success btn-file btn-xs" href="answer/download?ids='+row.id+'">下载报告</a>';
                    }else{
                        return '-';
                    }
                }
            },
        }
    };
    return Controller;
});